package chen.web.event.method;


/**
 * 方法事件, 在调用相关方法时会触发的事件. 这是一个底层的事件.
 * @author chen
 *
 */
public class MethodEvent {

	public static enum Status{before, after};
	
	private String type;
	private Status status;
	private Object[] params;
	private Result result;
	
	public String getType(){
		return type;
	}
	
	public MethodEvent(String type){
		this.type = type;
	}
	
	public Status getStatus(){
		return status;
	}
	
	void setStatus(Status status){
		this.status = status;
	}
	
	public Object[] getParams(){
		return params;
	}
	
	public <T> T getSingleParam(Class<T> clazz){
		for(Object obj : params){
			if(clazz.isInstance(obj)){
				return clazz.cast(obj); 
			}
		}
		throw new RuntimeException("找不能给定类型的参数, 事件:" + type + ",给定类型:" + clazz.getName());
	}
	
	void setParams(Object[] params){
		this.params = params;
	}
	
	void setResult(Result result){
		this.result = result;
	}
	
	public Result getResult(){
		return result;
	}
}
